package io.cici.cc.mybatis.plus.extension.p6spy;

import com.p6spy.engine.spy.appender.MessageFormattingStrategy;
import io.cici.cc.mybatis.plus.core.toolkit.StringUtils;

/**
 * P6spy SQL 打印策略
 */
public class P6SpyLogger implements MessageFormattingStrategy {

    @Override
    public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared,
                                String sql, String url) {
        return StringUtils.isNotBlank(sql)
                ? " Consume Time：" + elapsed + " ms " + now + "\n Execute SQL：" + sql.replaceAll("[\\s]+", " ") + "\n"
                : "";
    }
}
